#include "test_coll.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

int main(int argc, char* argv[])
{
	int n = 10000, d = 0;
	double exec_time, nInt;
	char *sd = "dr";

	if (argc == 1)
	{  
		printf("usage: seg_int -dD -nN\n");
		printf("example: seg_int -dp -n20000\n");
		printf("-nN: number of segments\n");
		printf("-dD: type of distribution\n");
		printf(" D = r: random segments\n");
		return 0;
	}
	else
	{
		for(int i = 1; i < argc; i++)
			if (argv[i][0] == '-') 
			{
				switch(argv[i][1])
				{
				case 'd':
					{
						switch(argv[i][2])
						{
						case 'd':d = debug;break;
						case 'r':d = random;break;
						default:
							{
								printf("some error in -d param. d used instead.\n");
								d = debug; 
							}
						};
					};
					break;
				case 'n':
					{
						n = atoi(argv[i] + 2);
						if (n < 2) 
						{
							n = 10000;
							printf("some error in -n param. 10000 used instead.\n");
						}
					}
					break;
				}
			}
	}
	printf("actual params is: -d%c -n%i\n", sd[d], n);
	PSeg *coll = create_test_collection(n, d);
	double start, stop;
	double c[8];
	int n_call = 0;
	start = clock();
	do
	{
		nInt = find_intersections(n, coll, c);
		stop = clock();
		n_call++;
	}
	while ((stop - start) < CLOCKS_PER_SEC);

	exec_time = (stop - start)/(n_call * CLOCKS_PER_SEC);
	printf("fast intersections = %13.0f time = %6.5f seconds\n", nInt, exec_time);
	delete_test_collection(coll);

	printf("Press 'Enter' to continue");
	getchar();
	return 0;
}